'''
Created on Dec 7, 2015

@author: JimmyMo
'''
import os.path
import glob
# from resourcecare.configuration.confignode import ConfigNode

class Locator(object):
    '''
    Locator is responsible for indicating and locating
    where the resources are.
    '''
    def __init__(self, enabled, name, locationPath, includeType=""):
        self.enabled = enabled
        self.name = name
        self.locationPath = locationPath
        self.includeType = includeType
        
    
    
    def do_locate(self):
        dir = self.locationPath
        onlydir = self.includeType == "_folder_"
        ext = self.includeType
        if not onlydir:
            extlist = [elem.strip() for elem in ext.split(",")];
#             list = [i for ext in extlist for i in glob.glob(os.path.join(dir, ext))]
            for ext in extlist:
                for i in glob.glob(os.path.join(dir, ext)):
                    yield i
        else:
            for j in os.listdir(dir):
                fullpath = os.path.join(dir, j)
                if os.path.isdir(fullpath):
                    yield fullpath